export const getUrlSearchByKey = (url: string,
    params: string[],
    returnArray = true
): string[] & Record<string, any> => {
    const search = new URL(url).search;
    const searchParams = new URLSearchParams(search);
    if (returnArray) {
        return params.map((key) => searchParams.get(key) as string);
    } else {
        const result: any = {};
        params.forEach((key) => {
            result[key] = searchParams.get(key);
        });
        return result;
    }
};


export const createFileByString = (textContent: string, fileName: string) => {
    const blob = new Blob([textContent], { type: 'text/plain' });
    const file = new File([blob], 'text-content.txt', { type: 'text/plain' });
    const formData = new FormData();
    formData.append('file', file);
    const requestOptions = {
        method: 'POST',
        body: formData,
    };
    fetch('https://www.doubao.com/samantha/chat/completion?aid=497858&device_id=7377217223036782134', requestOptions)
        .then(response => response.json())
        .then(data => console.log(data))
        .catch(error => console.error(error));
}
